home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr31 / hades.zip / CONVERT.C next >
C/C++ Source or Header  |  1992-04-14  |  4KB  |  186 lines

  1.  
  2. /***************
  3. **
  4. **  convert.c
  5. **  last revised: april 14, 1992
  6. **
  7. **  Convert version 1.00 alpha, Copyright (C)1992 Zabkar
  8. **  DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.
  9. **
  10. **  Convert converts a dictionary to all-uppercase, all-lowercase,
  11. **  name-alike (first uppercase, rest lowercase) and/or reversed words.
  12. **
  13. **  Usage: convert [-c] [-l] [-1] [-r] [-n] [-f wordfile] [-o outfile]
  14. **
  15. **  root@waves.hacktic.nl (Zabkar)
  16. **  root@room101.hacktic.nl (Remote)
  17. **
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include "dictword.h"
  23.  
  24.  
  25. FILE *outfile;
  26. FILE *infile;
  27.  
  28.  
  29. /***************
  30.  haltusage()
  31.  prints correct usage and exits
  32. ****************/
  33.  
  34. void haltusage()
  35. {
  36.   fprintf(stderr,
  37.   "Convert version 1.00 alpha, Copyright (C)1992 Zabkar\n"\
  38.   "DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.\n\n"\
  39.   "Usage: convert [-c] [-l] [-1] [-r] [-n] [-f wordfile] "\
  40.   "[-o outfile]\n\n"\
  41.   "\t-c: capitalize whole word\n"\
  42.   "\t-l: lowercase whole word\n"\
  43.   "\t-1: all lowercase, first uppercase\n"\
  44.   "\t-r: generate all selected options reversed, too\n"\
  45.   "\t-f: read from 'wordfile' instead of stdin\n"\
  46.   "\t-o: write to 'outfile' instead of stdout\n\n"\
  47.   "Use of one of the options c, l or 1 causes the normal word to disapear,\n"\
  48.   "to have the normal form back again, add the -n switch.\n\n"\
  49.   "no -f specified: wordfile read from stdin\n"\
  50.   "no -o specified: output written to stdout\n");
  51.   exit(0);
  52. }
  53.  
  54.  
  55.  
  56. /***************
  57.  convertwords()
  58.  converts words from file inf and writes them to file of.
  59. ****************/
  60.  
  61. void convertwords(FILE *inf, FILE *of, int mode)
  62. {
  63.     char word[80];
  64.     char buffer[80];
  65.     char dest[256];
  66.  
  67.     while (fscanf(inf, "%s", word) > 0)
  68.     {
  69.        strcpy(buffer, "");
  70.        if (mode & NORMAL || mode & EXTNORMAL)
  71.        {
  72.           strcat(buffer, word);
  73.           strcat(buffer, "\n");
  74.        }
  75.  
  76.        if (mode & LOWER)
  77.        {
  78.           strcat(buffer, all_lower(dest, word));
  79.           strcat(buffer, "\n");
  80.        }
  81.  
  82.        if (mode & UPPER)
  83.        {
  84.           strcat(buffer, all_upper(dest, word));
  85.           strcat(buffer, "\n");
  86.        }
  87.  
  88.        if (mode & FIRSTUP)
  89.        {
  90.           strcat(buffer, first_upper(dest, word));
  91.           strcat(buffer, "\n");
  92.        }
  93.  
  94.        if (mode & REVERSE)
  95.        {
  96.           reverse(dest, buffer);    /* reverse of all the above */
  97.           strcat(buffer, &dest[1]); /* strip leading newline */
  98.           strcat(buffer, "\n");     /* add line-feed to end */
  99.        }
  100.  
  101.        fprintf(of, "%s", buffer);   /* Print all words on of */
  102.     }
  103. }
  104.  
  105.  
  106.  
  107. /***************
  108.  main()
  109.  main function of program mailist
  110. ****************/
  111.  
  112. main(char argc, char **argv)
  113. {
  114.   char fname[80], oname[80];
  115.   int i;
  116.   int convmode = NORMAL;
  117.  
  118.   strcpy(fname, "");
  119.   strcpy(oname, "");
  120.  
  121.   if (argc > 1)
  122.   {
  123.     for (i=1; i<argc; i++)
  124.     {
  125.       switch(argv[i][0])
  126.       {
  127.       case '-': switch(toupper(argv[i][1]))
  128.           {
  129.             case 'F' : if (strlen(argv[i]) > 2)
  130.                  strcpy(fname, &argv[i][2]);
  131.                    else if (argc < (i+2))
  132.                  haltusage();
  133.                    else
  134.                  strcpy(fname, argv[++i]);
  135.                    break;
  136.             case 'O' : if (strlen(argv[i]) > 2)
  137.                  strcpy(oname, &argv[i][2]);
  138.                    else if (argc < (i+2))
  139.                  haltusage();
  140.                    else
  141.                  strcpy(oname, argv[++i]);
  142.                    break;
  143.             case 'C': convmode |= UPPER; convmode &= ~NORMAL; break;
  144.             case 'L': convmode |= LOWER; convmode &= ~NORMAL; break;
  145.             case '1': convmode |= FIRSTUP; convmode &= ~NORMAL; break;
  146.             case 'R': convmode |= REVERSE; break;
  147.             case 'N': convmode |= EXTNORMAL; break;
  148.             default  : haltusage();
  149.           }
  150.           break;
  151.       default : haltusage();
  152.       }
  153.     }
  154.   }
  155.  
  156.   if (strcmp(fname,""))
  157.     infile = fopen(fname, "rt");
  158.   else
  159.     infile = stdin;
  160.  
  161.   if (!infile)
  162.     {
  163.     fprintf(stderr, "convert: %s: couldn't open file\n", fname);
  164.     exit(0);
  165.     }
  166.  
  167.   if (strcmp(oname, ""))
  168.     outfile = fopen(oname, "wt");
  169.   else
  170.     outfile = stdout;
  171.  
  172.   if (!outfile)
  173.     {
  174.     fprintf(stderr, "convert: %s: could't create file\n", oname);
  175.     exit(0);
  176.     }
  177.  
  178.   convertwords(infile, outfile, convmode);
  179.  
  180.   fclose(infile);
  181.   fclose(outfile);
  182.  
  183.   }
  184.  
  185. /* EOF CONVERT.C */
  186.